<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Benchmark</title>
    <script type="text/javascript" src="benchmarker.js"></script>
    <script type="text/javascript">
      new Benchmarker(
        {},
        {
          atInit: function() {
            var len = 100; // the string, how long (in chars)?
            this.TEST = {
              NoMatch:    'a'.times(10).times(len/10),
              BeginMatch: ' a'.times(5).times(len/10),
              EndMatch:   'a '.times(5).times(len/10),
              BiMatch:    '  a  '.times(2).times(len/10)
            };
          },

          summary: 'string strip',
          description: 'two "simple" filters or a single "complex" one? ;-)',
          setup: function() {
            String.whitespace = ' \n\r\t\v\f\u00a0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000';
            Object.extend(String.prototype, {
              bm_strip1: function() {
                return this.replace(/(^\s+|\s+$)/g, '');
              },
              bm_strip2: function() {
                return this.replace(/^\s+/, '').replace(/\s+$/, '');
              },
              bm_strip3: function() {
                var i = 0, j = this.length - 1;
                while ( String.whitespace.indexOf( this.charAt(i) ) != -1 ) i++;
                while ( String.whitespace.indexOf( this.charAt(j) ) != -1 ) j--;
                return this.substring(i, j+1);
              }
            });
            $w('NoMatch BeginMatch EndMatch BiMatch').each(function(set) {
              methodSets.push({
                name: set,
                methods: {
                  oneRE: function() { return this.TEST[set].bm_strip1() },
                  twoRE: function() { return this.TEST[set].bm_strip2() },
                  noRE:  function() { return this.TEST[set].bm_strip3() }
                }
              });
            });
          }
        }
      );
    </script>
  </head>
  <body>
  </body>
</html>
